package kkk;

import static org.junit.Assert.assertTrue;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IRobotSnapshot;
import robocode.control.testing.RobotTestBed;

/**
 * Tests that Strafer moves and doesn't stay in the same spot.
 * 
 * @author Kyle Kakinami
 * 
 */
public class TestStraferWallAction extends RobotTestBed {
  /** True if the robot hits a wall. */
  boolean hitWall = false;
  boolean moveAwayFromWall = false;

  /**
   * Specifies that SittingDuck and Strafer are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SpinBot,kkk.Strafer*";
  }

  /**
   * This test runs for 5 round.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 5;
  }

  /**
   * Check to see if Strafer was previously near a wall, but no longer near a wall.
   * 
   * @param event Info about the current state of the battle.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    IRobotSnapshot robot = event.getTurnSnapshot().getRobots()[1];
    boolean nearWall =
        robot.getX() < 40 || robot.getY() < 40 || robot.getX() > (width - 40)
            || robot.getY() > (height - 40);
    if (nearWall) {
      hitWall = true;
    }
    if (hitWall && !nearWall) {
      moveAwayFromWall = true;
    }
  }

  /**
   * After the battle, check to see that we've moved away from the wall.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check if Strafer avoided the walls", moveAwayFromWall);
  }
}
